<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function handleData(x, y = 0) {
      let sum = 0
      for (let i = 0; i < array.length; i++) {
        sum += array[i]
      };
      if (y === 0 || y === true) {
        return sum
      }
      return sum / array.length
    };

    let res = handleData(array = [1, 2, 3, 5], false);
    console.log(res)
    let res1 = handleData(array = [1, 2, 3, 6], true);
    console.log(res1);


  </script>
</body>

</html>